<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo form_open('examiner/sendmark');

        echo '<table align="center" cellspacing="1" border="1" width=600px >';
        
        echo '<tr><td colspan=3 align=center>'.$id_te_sub.'のテスト</td></tr>';
        echo '
                
              <th>試験問題ID</th>
              <th>回答</th>
              <th>数点</th>
              ';
               $mark=0;
        foreach($list_ques_id as $row){
            echo "<tr>
                        <td >$row->id_question</td>
                        <td >$row->sub_an</td>";
            $query_tb=$this->db->query("select * from compare where id_question=$row->id_question");
            foreach($query_tb->result() as $row1)
            {
               $q=$row1->q; 
            }
            $this->db->select('*');
            $this->db->from($q);
            $this->db->where('id_question',$row->id_question);
            $query_q=$this->db->get();
            //print_r($query_q->result());
            echo "<td>";
            foreach ($query_q->result() as $row_q) {
            if($q=="q1")
            {
                //echo 10;
                if($row->sub_an==$row_q->an_ks)
                {
                   echo $row_q->sc; 
                   $mark=$mark+$row_q->sc;
                }
                else 
                    echo 0;
                echo "</br>";
            }
            else if($q=="q2")
            {
                        if($row->sub_an==substr($row_q->an_kso, 0,4)||$row->sub_an==substr($row_q->an_kso, 5,9))
                        {
                            echo $row_q->sc;
                            $mark=$mark+$row_q->sc;
                        }
                        else {
                            echo 0;
                        }
                  echo "<br>";  
            }
            else if($q=="q3")
            {
                if($row->sub_an==$row_q->an1_kw)
                {
                   echo $row_q->sc_an1; 
                   $mark=$mark+$row_q->sc_an1;
                }
                else if($row->sub_an==$row_q->an2_kw)
                {
                    echo $row_q->sc_an2;
                    $mark=$mark+$row_q->sc_an2;
                }
                else {
                    echo 0;
                }
            }
            else if($q=="q4")
            {
                if($row->sub_an==$row_q->an1_ks)
                {
                    echo $row_q->sc1;
                    $mark=$mark+$row_q->sc1;
                }
                else if($row->sub_an==$row_q->an2_ks)
                {
                    echo $row_q->sc2;
                    $mark=$mark+$row_q->sc2;
                }
                else if($row->sub_an==$row_q->an3_ksa)
                {
                    echo $row_q->sc3;
                    $mark=$mark+$row_q->sc3;
                }
            else {
                echo $row_q->sc4;
                $mark=$mark+$row_q->sc4;
            }
            }
            else if($q=="q5")
            {
                if($row->sub_an=="コミュニケーションチームワークリーダシップ")
                {
                    echo 30;
                    $mark=$mark+30;
                }
                else if($row->sub_an=="コミュニケーション")
                {
                    echo 10;
                    $mark=$mark+10;
                }
                else if($row->sub_an=="チームワーク")
                {
                    echo 10;
                    $mark=$mark+10;
                }
                else if($row->sub_an=="リーダシップ")
                {
                    echo 10;
                    $mark=$mark+10;
                }
                else 
                    echo 0;
            }
            else if($q=="q6")
            {
                $sub_an_l=  explode("/", $row->sub_an);
                $sub_an1=$sub_an_l[0];
                $sub_an2=$sub_an_l[1];
                $sub_an3=$sub_an_l[2];
                $sub_an12=$sub_an1.",".$sub_an2;
                $sub_an13=$sub_an1.",".$sub_an3;
                $sub_an23=$sub_an2.",".$sub_an3;
                if($sub_an12==$row_q->an1_kwpo||$sub_an13==$row_q->an1_kwpo||$sub_an23==$row_q->an1_kwpo)
                {
                    echo $row_q->sc1;
                    $mark=$mark+$row_q->sc1;
                }
                else if($sub_an12==$row_q->an2_kwpo||$sub_an13==$row_q->an2_kwpo||$sub_an23==$row_q->an2_kwpo)
                {
                    echo $row_q->sc2;
                    $mark=$mark+$row_q->sc2;
                }
                else if($sub_an12==$row_q->an3_kwpo||$sub_an13==$row_q->an3_kwpo||$sub_an23==$row_q->an3_kwpo)
                {
                    echo $row_q->sc3;
                    $mark=$mark+$row_q->sc3;
                }
                else
                {
                    echo $row_q->sc4;
                    $mark=$mark+$row_q->sc4;
                }
            }
        
            }  
            echo "</td>";  
        }?> 

    <?php
        echo "<tr>
                        <td colspan=3 align=center>点の合計：$mark</td>
              </tr>";?>
        <?php 
        echo '</table>';
        $this->db->select('*');
        $this->db->from('tester');
        $this->db->where('id_te',$id_te_sub);
        $query_tester=$this->db->get();
        if($query_tester->num_rows()>=1)
        {
            $update_submit=array(
            'sum_mark'=>$mark

        );
        $this->db->update('tester',$update_submit,array('id_te'=>$id_te_sub));
        }
        else {
            $data = array(  
            'id_te'=>$id_te_sub,                  
            'sum_mark'=>$mark
                    );
            $this->db->insert('tester',$data);
        }
        
?>
</form>
</body>
</html>
